from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-29 14:09:12.603001
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 29, Jan, 2021
Time: 14:09:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6409
Nobs: 186.000 HQIC: -46.5692
Log likelihood: 2104.46 FPE: 3.16925e-21
AIC: -47.2017 Det(Omega_mle): 1.97819e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437978 0.141265 3.100 0.002
L1.Burgenland 0.128240 0.074156 1.729 0.084
L1.Kärnten -0.230725 0.060758 -3.797 0.000
L1.Niederösterreich 0.133438 0.169848 0.786 0.432
L1.Oberösterreich 0.215579 0.148334 1.453 0.146
L1.Salzburg 0.195289 0.078645 2.483 0.013
L1.Steiermark 0.095945 0.105966 0.905 0.365
L1.Tirol 0.160940 0.070835 2.272 0.023
L1.Vorarlberg -0.002199 0.066376 -0.033 0.974
L1.Wien -0.121179 0.142455 -0.851 0.395
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.500725 0.179438 2.791 0.005
L1.Burgenland 0.015069 0.094194 0.160 0.873
L1.Kärnten 0.368536 0.077177 4.775 0.000
L1.Niederösterreich 0.113977 0.215745 0.528 0.597
L1.Oberösterreich -0.150854 0.188417 -0.801 0.423
L1.Salzburg 0.191909 0.099896 1.921 0.055
L1.Steiermark 0.240602 0.134601 1.788 0.074
L1.Tirol 0.137524 0.089977 1.528 0.126
L1.Vorarlberg 0.178055 0.084312 2.112 0.035
L1.Wien -0.583498 0.180949 -3.225 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.291267 0.063585 4.581 0.000
L1.Burgenland 0.114425 0.033378 3.428 0.001
L1.Kärnten -0.024931 0.027348 -0.912 0.362
L1.Niederösterreich 0.064378 0.076450 0.842 0.400
L1.Oberösterreich 0.285463 0.066767 4.276 0.000
L1.Salzburg 0.006646 0.035399 0.188 0.851
L1.Steiermark -0.022502 0.047697 -0.472 0.637
L1.Tirol 0.093243 0.031884 2.924 0.003
L1.Vorarlberg 0.116857 0.029877 3.911 0.000
L1.Wien 0.079969 0.064120 1.247 0.212
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213072 0.072919 2.922 0.003
L1.Burgenland -0.007978 0.038278 -0.208 0.835
L1.Kärnten 0.023013 0.031363 0.734 0.463
L1.Niederösterreich 0.031162 0.087673 0.355 0.722
L1.Oberösterreich 0.386239 0.076568 5.044 0.000
L1.Salzburg 0.097289 0.040595 2.397 0.017
L1.Steiermark 0.182617 0.054698 3.339 0.001
L1.Tirol 0.041785 0.036564 1.143 0.253
L1.Vorarlberg 0.093757 0.034262 2.736 0.006
L1.Wien -0.063551 0.073533 -0.864 0.387
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.522842 0.145743 3.587 0.000
L1.Burgenland 0.077233 0.076506 1.009 0.313
L1.Kärnten 0.006399 0.062684 0.102 0.919
L1.Niederösterreich -0.011169 0.175232 -0.064 0.949
L1.Oberösterreich 0.154452 0.153036 1.009 0.313
L1.Salzburg 0.057271 0.081138 0.706 0.480
L1.Steiermark 0.110491 0.109325 1.011 0.312
L1.Tirol 0.213179 0.073081 2.917 0.004
L1.Vorarlberg 0.016941 0.068480 0.247 0.805
L1.Wien -0.135738 0.146970 -0.924 0.356
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154944 0.103222 1.501 0.133
L1.Burgenland -0.016819 0.054186 -0.310 0.756
L1.Kärnten -0.014229 0.044396 -0.321 0.749
L1.Niederösterreich 0.125559 0.124108 1.012 0.312
L1.Oberösterreich 0.391770 0.108388 3.615 0.000
L1.Salzburg -0.023855 0.057466 -0.415 0.678
L1.Steiermark -0.032396 0.077430 -0.418 0.676
L1.Tirol 0.190025 0.051759 3.671 0.000
L1.Vorarlberg 0.046576 0.048501 0.960 0.337
L1.Wien 0.185632 0.104092 1.783 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.213877 0.131704 1.624 0.104
L1.Burgenland 0.088426 0.069137 1.279 0.201
L1.Kärnten -0.044101 0.056646 -0.779 0.436
L1.Niederösterreich -0.020617 0.158352 -0.130 0.896
L1.Oberösterreich -0.109744 0.138294 -0.794 0.427
L1.Salzburg 0.033162 0.073322 0.452 0.651
L1.Steiermark 0.388562 0.098794 3.933 0.000
L1.Tirol 0.494209 0.066041 7.483 0.000
L1.Vorarlberg 0.176356 0.061884 2.850 0.004
L1.Wien -0.219113 0.132813 -1.650 0.099
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.084752 0.160467 0.528 0.597
L1.Burgenland 0.030020 0.084236 0.356 0.722
L1.Kärnten -0.093022 0.069017 -1.348 0.178
L1.Niederösterreich 0.247678 0.192935 1.284 0.199
L1.Oberösterreich -0.000812 0.168497 -0.005 0.996
L1.Salzburg 0.233156 0.089335 2.610 0.009
L1.Steiermark 0.123398 0.120370 1.025 0.305
L1.Tirol 0.078064 0.080464 0.970 0.332
L1.Vorarlberg 0.036852 0.075398 0.489 0.625
L1.Wien 0.267561 0.161818 1.653 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.581008 0.084124 6.907 0.000
L1.Burgenland -0.019085 0.044160 -0.432 0.666
L1.Kärnten -0.002296 0.036182 -0.063 0.949
L1.Niederösterreich -0.040174 0.101146 -0.397 0.691
L1.Oberösterreich 0.282953 0.088334 3.203 0.001
L1.Salzburg 0.017862 0.046833 0.381 0.703
L1.Steiermark 0.013764 0.063104 0.218 0.827
L1.Tirol 0.079425 0.042183 1.883 0.060
L1.Vorarlberg 0.150729 0.039528 3.813 0.000
L1.Wien -0.060433 0.084833 -0.712 0.476
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.152450 0.002262 0.208239 0.255440 0.068856 0.066759 -0.051027 0.168391
Kärnten 0.152450 1.000000 0.020357 0.194035 0.165459 -0.114480 0.171590 0.024032 0.315971
Niederösterreich 0.002262 0.020357 1.000000 0.301500 0.080588 0.215158 0.124521 0.058489 0.360940
Oberösterreich 0.208239 0.194035 0.301500 1.000000 0.298343 0.302473 0.102499 0.083936 0.126284
Salzburg 0.255440 0.165459 0.080588 0.298343 1.000000 0.155283 0.052704 0.083451 -0.016764
Steiermark 0.068856 -0.114480 0.215158 0.302473 0.155283 1.000000 0.107949 0.096325 -0.097529
Tirol 0.066759 0.171590 0.124521 0.102499 0.052704 0.107949 1.000000 0.173121 0.145285
Vorarlberg -0.051027 0.024032 0.058489 0.083936 0.083451 0.096325 0.173121 1.000000 0.080489
Wien 0.168391 0.315971 0.360940 0.126284 -0.016764 -0.097529 0.145285 0.080489 1.000000